package com.kaesar.thread_ressmix.atomic;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @Author: chengk
 * @Date: 2021/8/30 7:37 下午
 */
public class UnsafeTest {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        // 这种方式获取不到 unsafe
        // Unsafe unsafe = Unsafe.getUnsafe();

        // 通过反射的方式获取 unsafe
        Field f = Unsafe.class.getDeclaredField("theUnsafe");
        f.setAccessible(true);
        Unsafe unsafe = (Unsafe) f.get(null);

        System.out.println(unsafe);
    }
}
